//
//  YBRedEnvelopeCell.m
//  yibeilive
//
//  Created by Itisnotthathard on 2022/11/18.
//

#import "YBRedEnvelopeCell.h"

@implementation YBRedEnvelopeCell

// 初始化控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _redBagIconImgV = UIImageView.new;
        _redBagIconImgV.image = [UIImage imageNamed:@"msg_bubble_redbag_icon"];
        [self.container addSubview:_redBagIconImgV];

        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.numberOfLines = 1;
        _titleLabel.text = @"恭喜发财，大吉大利";
        [self.container addSubview:_titleLabel];

        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.font = [UIFont systemFontOfSize:11];
        _subTitleLabel.textColor = [UIColor whiteColor];
        _subTitleLabel.textAlignment = NSTextAlignmentLeft;
        _subTitleLabel.numberOfLines = 1;
        _subTitleLabel.text = @"领取红包";
        [self.container addSubview:_subTitleLabel];

        _fromLabel = [[UILabel alloc] init];
        _fromLabel.font = [UIFont systemFontOfSize:9 weight:UIFontWeightMedium];
        _fromLabel.textColor = kUIColorFromRGB(0xB0B0B0);
        _fromLabel.textAlignment = NSTextAlignmentLeft;
        _fromLabel.numberOfLines = 1;
        _fromLabel.text = @"伊贝红包";
        [self.container addSubview:_fromLabel];
    }
    return self;
}

// 根据 cellData 绘制 cell
- (void)fillWithData:(YBRedEnvelopeCellData *)data {
    [super fillWithData:data];

    self.customData = data;
    
    self.titleLabel.text = data.message;
    if (data.direction == MsgDirectionIncoming) {
        self.bubbleView.image = [UIImage imageNamed:@"msg_bubble_redbag_bg_left"];
    }else{
        self.bubbleView.image = [UIImage imageNamed:@"msg_bubble_redbag_bg_right"];
    }
}

// 设置控件坐标
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.redBagIconImgV.mm_width(38).mm_height(38).mm_left(12).mm_top(10);
    self.titleLabel.mm_height(17).mm_left(self.redBagIconImgV.mm_maxX + 2).mm_flexToRight(12).mm_top(12);
    self.subTitleLabel.mm_height(15).mm_left(self.redBagIconImgV.mm_maxX + 2).mm_flexToRight(12).mm_top(self.titleLabel.mm_maxY + 3);
    self.fromLabel.mm_height(13).mm_left(18).mm_flexToRight(12).mm_bottom(3);
}

@end
